﻿
Partial Class Site
    Inherits System.Web.UI.MasterPage

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Page.IsPostBack = False Then
            Call cargarMenuPrincipal()
        End If
        'Verificarsihaysubmodulo
        If String.IsNullOrEmpty(Request.QueryString("CodModulo")) = False AndAlso IsNumeric(Request.QueryString("CodModulo")) Then
            Dim hp As New Helper()
            hp.verficarSeguridad(Context.User.Identity.Name, Request.QueryString("CodModulo"), Page)
            'Cargar los submodulos
            If Page.IsPostBack = False Then
                CargarSubmenu(Context.User.Identity.Name, Request.QueryString("CodModulo"))
            End If
        End If
    End Sub
    Sub verficarSeguridad(ByVal usuario As String, ByVal codModulo As Integer)
        Dim bd As New bdSeguridadDataContext()
        Dim permiso = bd.Web_SP_GetPermisoModulo(usuario, codModulo)
        If permiso.First.Permiso = 0 Then
            Session.Abandon()
            FormsAuthentication.SignOut()
            FormsAuthentication.RedirectToLoginPage()
        End If
    End Sub
    Sub cargarMenuPrincipal()
        'cargar el menú
        Dim bd As New bdSeguridadDataContext()
        Dim Usuario = Context.User.Identity.Name
        Dim menu = bd.Web_SP_ModulosXUsuario(Usuario)
        Repeater1.DataSource = menu
        Repeater1.DataBind()
    End Sub
    Sub CargarSubmenu(ByVal usuario As String, ByVal codMenu As Integer)
        Dim bd As New bdSeguridadDataContext()
        Dim menu = bd.Web_SP_SubModulosXUsuario(usuario, codMenu)
        Repeater2.DataSource = menu
        Repeater2.DataBind()
    End Sub

    Protected Sub lnkSalir_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkSalir.Click
        Session.Abandon()
        FormsAuthentication.SignOut()
        Response.Redirect("~/Default.aspx")
        Response.Cookies.Clear()
    End Sub
End Class

